package conf

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"time"
)

type conf struct {
	MysqlUser string 	`yaml:"mysqlUser"`
	MysqlPass string 	`yaml:"mysqlPass"`
	MysqlUrls string 	`yaml:"mysqlUrls"`
	MysqlDb string 		`yaml:"mysqlDb"`
	RunMode string		`yaml:"RUN_MODE"`
	ReadTimeout int 	`yaml:"READ_TIMEOUT"`
	WriteTimeout int 	`yaml:"WRITE_TIMEOUT"`
	HttpPort int		`yaml:"HTTP_PORT"`
	RedisHost string	`yaml:"RedisHost"`
	RedisPassword string `yaml:"RedisPassword"`
	RedisMaxIdle int	`yaml:"RedisMaxIdle"`
	RedisMaxActive int `yaml:"RedisMaxActive"`
	RedisIdleTimeout int `yaml:"RedisIdleTimeout"`
}


var (
	MysqlUser 		string
	MysqlPass 		string
	MysqlUrls 		string
	MysqlDb			string
	RunMode			string
	ReadTimeout		time.Duration
	WriteTimeout	time.Duration
	HttpPort		int
	RedisHost 		string
	RedisPassword 	string
	RedisMaxIdle 	int
	RedisMaxActive 	int
	RedisIdleTimeout time.Duration
)

func (c *conf) GetConf() *conf {
	yamlFile, err := ioutil.ReadFile("conf/app.yaml")
	if err != nil {
		fmt.Println(err.Error())
	}
	err = yaml.Unmarshal(yamlFile, c)
	if err != nil {
		fmt.Println(err.Error())
	}
	return c
}

func init() {
	var c conf
	conf := c.GetConf()
	MysqlUser = conf.MysqlUser
	MysqlPass = conf.MysqlPass
	MysqlUrls = conf.MysqlUrls
	MysqlDb = conf.MysqlDb
	RunMode = conf.RunMode
	ReadTimeout = time.Duration(conf.ReadTimeout) * time.Second
	WriteTimeout = time.Duration(conf.WriteTimeout) * time.Second
	HttpPort = conf.HttpPort
	RedisHost = conf.RedisHost
	RedisPassword = conf.RedisPassword
	RedisMaxIdle = conf.RedisMaxIdle
	RedisMaxActive = conf.RedisMaxActive
	RedisIdleTimeout = time.Duration(conf.RedisIdleTimeout) * time.Second
	fmt.Println(moha)
}

var moha = `

            $$$$$$$$$$$$$$$       $$$$$$$$$$$$$$$%.
         &$               &$    =$                $         
         $                 $$$$$$=                @&        
      B=$$                 $$$$$$                  $$&=     
      $$$$      +1s        $$&-$$       +1s        $$$      
      $$$$                 $-   $                  $$$      
         $                 $    $                  .B        
         $                 @    $                 .=        
          $                $     $                %         
           $            =$         =$            @&          
            #$$$$$$$$$%              -@$$$$$$$$B            
                                                            
                      莫生        莫生
                       气         气

                       代码辣鸡非我意,
                       自己动手分田地;
                       你若气死谁如意?
                       谈笑风生活长命.

`
